import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sweetim/model/member_info.dart';
import 'package:sweetim/service/login_service.dart';
import 'package:sweetim/service/member_service.dart';

class LoginController extends GetxController {
  final MemberService _memberService = Get.find();
  final LoginService _loginService = Get.put(LoginService());

  var loading = false.obs;

  final formKey = GlobalKey<FormState>();
  final unameController = TextEditingController();
  final pwdController = TextEditingController();

  login(String phone, String pwd) async {
    loading.value = true;
    Get.log("phone: ${phone}, pwd: ${pwd}");
    MemberInfo? memberInfo =  await _loginService.login(phone, pwd);
    Get.log("memberInfo: ${memberInfo ?? "error"}");
    loading.value = false;
    if(memberInfo != null) {
      Get.snackbar("欢迎回来", "👏${memberInfo.m?.name ?? "无名氏"}");
      await _memberService.putInfo(memberInfo);
      Get.offAndToNamed("/home");
    }
  }


}